# $Id$
# Maintainer: AndyRTR <andyrtr@archlinux.org>

pkgbase=hunspell-en
pkgname=('hunspell-en_US' 'hunspell-en_AU' 'hunspell-en_CA' 'hunspell-en_GB')
pkgver=2018.04.16
pkgrel=5
pkgdesc="English hunspell dictionaries"
arch=(any)
url="http://wordlist.aspell.net/dicts/"
license=('LGPL' 'custom:scowl')
optdepends=('hunspell: the spell checking libraries and apps')
source=(http://downloads.sourceforge.net/project/wordlist/speller/$pkgver/hunspell-en_US-large-$pkgver.zip
        http://downloads.sourceforge.net/project/wordlist/speller/$pkgver/hunspell-en_AU-large-$pkgver.zip
        http://downloads.sourceforge.net/project/wordlist/speller/$pkgver/hunspell-en_CA-large-$pkgver.zip
        http://downloads.sourceforge.net/project/wordlist/speller/$pkgver/hunspell-en_GB-large-$pkgver.zip)
sha1sums=('fd187bef6c15c10712a8aba1bbff563bb3533ceb'
          'a0edc7fd6aeb1ebd2aca01e06295d7afc4cd681d'
          'faf7015b8ebebbd4599dda8512013e9f296b9f80'
          'a5d9771655c1674d6544f96b75cacc64c1397172')

prepare() {
  sed -i "s:SET UTF8:SET UTF-8:g" *.aff
}

package_hunspell-en_US() {
  pkgdesc="US English hunspell dictionaries"
  replaces=('hunspell-en')
  conflicts=('hunspell-en')

  cd "$srcdir"
  install -dm755 ${pkgdir}/usr/share/hunspell
  install -m644 en_US*.dic en_US*.aff $pkgdir/usr/share/hunspell

  pushd $pkgdir/usr/share/hunspell/
    en_US_aliases="en_PH en_US"
    for lang in $en_US_aliases; do
      ln -s en_US-large.aff $lang.aff
      ln -s en_US-large.dic $lang.dic
    done
  popd

  # myspell symlinks
  install -dm755 ${pkgdir}/usr/share/myspell/dicts
  pushd $pkgdir/usr/share/myspell/dicts
    for file in $pkgdir/usr/share/hunspell/*; do
      ln -sv /usr/share/hunspell/$(basename $file) .
    done
  popd

  # licenses
  install -D -m644 README_en_US-large.txt $pkgdir/usr/share/licenses/$pkgname/Copyright_en_US-large
}

package_hunspell-en_AU() {
  pkgdesc="AU English hunspell dictionaries"
  replaces=('hunspell-en')
  conflicts=('hunspell-en')

  cd "$srcdir"
  install -dm755 ${pkgdir}/usr/share/hunspell
  install -m644 en_AU*.dic en_AU*.aff $pkgdir/usr/share/hunspell

  pushd $pkgdir/usr/share/hunspell/
    en_AU_aliases="en_AU"
    for lang in $en_AU_aliases; do
      ln -s en_AU-large.aff $lang.aff
      ln -s en_AU-large.dic $lang.dic
    done
  popd

  # myspell symlinks
  install -dm755 ${pkgdir}/usr/share/myspell/dicts
  pushd $pkgdir/usr/share/myspell/dicts
    for file in $pkgdir/usr/share/hunspell/*; do
      ln -sv /usr/share/hunspell/$(basename $file) .
    done
  popd

  # licenses
  install -D -m644 README_en_AU-large.txt $pkgdir/usr/share/licenses/$pkgname/Copyright_en_AU-large
}

package_hunspell-en_CA() {
  pkgdesc="CA English hunspell dictionaries"
  replaces=('hunspell-en')
  conflicts=('hunspell-en')

  cd "$srcdir"
  install -dm755 ${pkgdir}/usr/share/hunspell
  install -m644 en_CA*.dic en_CA*.aff $pkgdir/usr/share/hunspell

  pushd $pkgdir/usr/share/hunspell/
    en_CA_aliases="en_CA"
    for lang in $en_CA_aliases; do
      ln -s en_CA-large.aff $lang.aff
      ln -s en_CA-large.dic $lang.dic
    done
  popd

  # myspell symlinks
  install -dm755 ${pkgdir}/usr/share/myspell/dicts
  pushd $pkgdir/usr/share/myspell/dicts
    for file in $pkgdir/usr/share/hunspell/*; do
      ln -sv /usr/share/hunspell/$(basename $file) .
    done
  popd

  # licenses
  install -D -m644 README_en_CA-large.txt $pkgdir/usr/share/licenses/$pkgname/Copyright_en_CA-large
}

package_hunspell-en_GB() {
  pkgdesc="GB English hunspell dictionaries"
  replaces=('hunspell-en')
  conflicts=('hunspell-en')

  cd "$srcdir"
  install -dm755 ${pkgdir}/usr/share/hunspell
  install -m644 en_GB*.dic en_GB*.aff $pkgdir/usr/share/hunspell

  pushd $pkgdir/usr/share/hunspell/
    en_GB_aliases="en_AG en_BS en_BW en_BZ en_DK en_GB en_GH en_HK en_IE en_IN en_JM en_NA en_NG en_NZ en_SG en_TT en_ZA en_ZW"
    for lang in $en_GB_aliases; do
      ln -s en_GB-large.aff $lang.aff
      ln -s en_GB-large.dic $lang.dic
    done
  popd

  # myspell symlinks
  install -dm755 ${pkgdir}/usr/share/myspell/dicts
  pushd $pkgdir/usr/share/myspell/dicts
    for file in $pkgdir/usr/share/hunspell/*; do
      ln -sv /usr/share/hunspell/$(basename $file) .
    done
  popd

  # licenses
  install -D -m644 README_en_GB-large.txt $pkgdir/usr/share/licenses/$pkgname/Copyright_en_GB-large
}
